﻿package
{
   import casts.preloader.preloader_main;
   
   import command.DoTweenMax;
   
   import flash.events.Event;
   import flash.net.URLRequest;
   
   import jp.progression.casts.CastPreloader;
   import jp.progression.executors.CommandExecutor;
	
	/**
	 * @author  cjboy1984@gmail.com
	 */
	public class _Preloader extends CastPreloader
	{
      private var mcPerc:preloader_main = new preloader_main();

		public function _Preloader()
		{
			super( new URLRequest( "index.swf" ), false, CommandExecutor );
		}

      // ################### protected ##################

		override protected function atReady():void
		{
         mcPerc.alpha = 0;
         foreground.addChild(mcPerc);
		}

		override protected function atCastLoadStart():void
		{
         onStageResize();
         stage.addEventListener(Event.RESIZE, onStageResize);

         addCommand(
            new DoTweenMax(mcPerc, 0.4, { alpha:1 } )
         );
		}

		override protected function atProgress():void
		{
         // do something
		}

		override protected function atCastLoadComplete():void
		{
         addCommand(
            new DoTweenMax(mcPerc, 0.4, { alpha:0, onComplete:mcPerc.removeIt } )
         );
		}

      // #################### private ###################

      // --------------------- LINE ---------------------

      private function onStageResize(e:Event = null):void
      {
         mcPerc.x = sw / 2;
         mcPerc.y = sh / 2;
      }

      public function get sw():Number { return stage.stageWidth; }
      public function get sh():Number { return stage.stageHeight; }

      // --------------------- LINE ---------------------

	}

}
